<template>
  <div
    class="menu-management-container no-background-container table-auto-height"
  >
    <el-row :gutter="20">
      <el-col :lg="4" :md="8" :sm="24" :xl="4" :xs="24">
        <el-card>
          <el-tree
            :data="treeList"
            :default-expanded-keys="['home']"
            node-key="name"
            :props="defaultProps"
            @node-click="handleNodeClick"
          />
        </el-card>
      </el-col>
      <el-col :lg="20" :md="16" :sm="24" :xl="20" :xs="24">
        <el-card>
          <el-table
            v-loading="listLoading"
            border
            :data="list"
            row-key="name"
            :tree-props="{ children: 'children', hasChildren: true }"
          >
            <el-table-column
              label="标题"
              prop="meta.title"
              align="center"
              min-width="140"
              show-overflow-tooltip
            />
            <el-table-column
              prop="name"
              label="name"
              align="center"
              min-width="120"
              show-overflow-tooltip
            />
            <el-table-column
              label="路径"
              prop="path"
              align="center"
              min-width="140"
              show-overflow-tooltip
            />
            <el-table-column align="center" label="图标">
              <template #default="{ row }">
                <Icons v-if="row?.meta?.icon" :name="row?.meta?.icon" />
              </template>
            </el-table-column>
            <el-table-column align="center" label="是否隐藏菜单">
              <template #default="{ row }">
                <el-tag v-if="row?.meta?.hidden" class="ml-2" type="success">
                  是
                </el-tag>
                <el-tag v-else class="ml-2" type="danger">否</el-tag>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              label="vue文件路径"
              min-width="120"
              prop="component"
              show-overflow-tooltip
            >
              <template #default="{ row }">
                {{ row.children ? "--" : row.component }}
              </template>
            </el-table-column>
            <template #empty>
              <el-empty class="vab-data-empty" description="暂无数据" />
            </template>
          </el-table>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
  import { Plus } from "@element-plus/icons-vue";
  import { layoutMap } from "/@/router/router";
  import _ from "lodash";
  import { StrSplit } from "/@/utils/utils";

  const editRef = ref(null);
  const treeList = ref([]);
  const defaultProps = reactive({
    children: "children",
    label: "name",
  });
  const list = ref([]);
  const listLoading = ref(true);

  const handleEdit = (row = {}) => {
    editRef.value.showEdit(row);
  };

  const handleDelete = (row = {}) => {
    if (row.path) {
    }
  };

  const fetchData = async (role = {}) => {
    listLoading.value = true;
    list.value = layoutMap;
    listLoading.value = false;
  };

  const handleNodeClick = ({ role }) => {
    fetchData(role);
  };

  onBeforeMount(() => {
    treeList.value = layoutMap;
    fetchData();
  });
</script>
